<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/17
 * Time: 21:38
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller;

use app\common\business\Yu as BusObj;
use app\common\lib\Show;
use app\common\lib\Status;
use think\App;
use think\Exception;

class Yu extends Base
{
    protected BusObj $busObj;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->busObj = new BusObj();
    }

    public function index()
    {
        $this->indexField = "*,fatherOpenid as fatherUser";
        $name = $this->request->param('name', '', 'trim');
        $mobile = $this->request->param('mobile', '', 'trim');
        $city = $this->request->param('city', '', 'trim');
        $nickname = $this->request->param('nickname', '', 'trim');
        if (!empty($name)) {
            $this->indexWhere[] = [
                ['name', 'like', "%{$name}%"]
            ];
        }
        if (!empty($mobile)) {
            $this->indexWhere[] = [
                ['mobile', 'like', "%{$mobile}%"]
            ];
        }
        if (!empty($city)) {
            $this->indexWhere[] = [
                ['city', 'like', "%{$city}%"]
            ];
        }
        if (!empty($nickname)) {
            //根据relname查询
            try {
                $wechat = (new \app\common\business\Wechat())->getWechatByRealNameByIds($nickname);
            } catch (\Exception $e) {
                return Show::json_show(Status::status_error, $e->getMessage());
            }
            $this->indexWhere[] = [
                ['fatherOpenid', 'in', array_column($wechat, 'openid')]
            ];
        }
        return parent::index(); // TODO: Change the autogenerated stub
    }
}